<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*,entry.*,service.*"%>
<% String path = request.getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>CoolMeeting会议管理系统</title>
<link rel="stylesheet" href="../styles/common.css" />
<script type="text/javascript" src="../js/jquery-1.8.3.js"></script>
<script type="text/javascript">
	var xmlHttp;
	//1.创建ajax引擎
	function createXMLHttprequest() {
		if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlHttp = new XMLHttpRequest();
		} else {// code for IE6, IE5
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	function validate() {
		createXMLHttprequest();
		//1.获取用户名节点
		var accountname = document.getElementById("accountname");
		//设置跳转的路径
		
		var url = "../VUS?accountname=" + escape(accountname.value);
		alert(url);
		//打开连接
		xmlHttp.open("GET", url, true);
		//当xmlHttp的状态发生改变时调用callback
		xmlHttp.onreadystatechange = callback;
		//将请求发送到服务器
		xmlHttp.send(null);

	}

	//ajax响应
	function callback() {
		//请求已经完成，且响应已经就绪
		if (xmlHttp.readyState == 4) {
			if (xmlHttp.status == 200) {
				//获取响应的数据
				var message = xmlHttp.responseXML.getElementsByTagName("message")[0].firstChild.data;
				var passed = xmlHttp.responseXML.getElementsByTagName("passed")[0].firstChild.data;
				//根据响应的数据，显示在界面中
				setMessage(message, passed);
			}
		}
	}

	//根据响应的数据，显示在界面中
	function setMessage(message, passed) {
		var validateMessage = document.getElementById("accountnamespan");
		var color = "red";
		if (passed == "true") {
			color = "green";
		}
		validateMessage.innerHTML = "<font color="+color+">" + message
				+ "</font>";
	}

	$(document).ready(function() {
		$("#employeename").blur(function() {
			var val = $(this).val();
			if (val == "") {
				$("#employeenamespan").html("姓名必须填写！");
				return false;
			}
			/* if(val.length < 8 || val.length > 16) {
				$("#employeenamespan").html("长度");
				$(this).val("");
			} */
		});
	});
	$(document).ready(function() {
		//$("#accountname").blur(validate);

		$("#accountname").blur(function() {
			var val = $(this).val();
			
			if(val == ""){
				$("#accountnamespan").html("帐户名必须填写！");
				return false;
			}
			if(val.length < 6){
				$("#accountnamespan").html("账号长度不够！");
				return false;
			}
			var accountname = /^[0-9a-zA-Z]{6,} $/;
			if(!accountname.text(val)) {
				$("#accountnamespan").html("包含非法字符！");
				$(this).val("");
			}
		
		}); 
	});

	$(document).ready(function() {
		$("#password").blur(function() {
			var val = $(this).val();
			if (val == "") {
				$("#passwordspan").html("密码名必须填写！");
				return false;
			}
			if (val.length < 6) {
				$("#passwordspan").html("密码长度不够！");
				return false;
			}
		});
	});
	$(document).ready(function() {
		$("#confirm").blur(function() {
			var val = $(this).val();
			var psdval = $("#password").val();

			if (val != psdval) {
				$("#passwordspan").html("密码不一致！");
				$(this).val("");
			}

		});
	});
	$(document).ready(function() {
		$("#phone").blue(function() {
			var filter = /^1\d{10}$/;
			var val = $(this).val();
			if (filter.test(val) == false) {
				$("#phonespan").html("手机号码输入错误！");
				$(this).val("");
			}
		});
	});
	$(document).ready(function() {
			$("#email").blue(function() {
				var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				var val = $(this).val();
				if (filter.test(val) == false) {
					$("#emailspan").html("邮箱输入错误！");
					$(this).val("");
				}
			});
	});
</script>
<style type="text/css">
</style>
</head>
<body>
	<div class="page-header">
		<div class="header-banner">
			<img src="../images/header.png" alt="CoolMeeting" />
		</div>
		<div class="header-title">欢迎访问Cool-Meeting会议管理系统</div>
		<div class="header-quicklink">
			欢迎您，<strong>admin</strong> <a href="changepassword.html">[修改密码]</a>
		</div>
	</div>
	<div class="page-body">
		<div class="page-sidebar">
			<div class="sidebar-menugroup">
				<div class="sidebar-grouptitle">个人中心</div>
				<ul class="sidebar-menu">
					<li class="sidebar-menuitem"><a href="notifications.html">最新通知</a></li>
					<li class="sidebar-menuitem active"><a href="mybookings.html">我的预定</a></li>
					<li class="sidebar-menuitem"><a href="mymeetings.html">我的会议</a></li>
				</ul>
			</div>
			<div class="sidebar-menugroup">
				<div class="sidebar-grouptitle">人员管理</div>
				<ul class="sidebar-menu">
					<li class="sidebar-menuitem"><a href="departments.html">部门管理</></li>
					<li class="sidebar-menuitem"><a href="register.jsp">员工注册</a></li>
					<li class="sidebar-menuitem"><a href="approveaccount.html">注册审批</a></li>
					<li class="sidebar-menuitem"><a href="searchemployees.html">搜索员工</a></li>
				</ul>
			</div>
			<div class="sidebar-menugroup">
				<div class="sidebar-grouptitle">会议预定</div>
				<ul class="sidebar-menu">
					<li class="sidebar-menuitem"><a href="addmeetingroom.html">添加会议室</a></li>
					<li class="sidebar-menuitem"><a href="meetingrooms.html">查看会议室</a></li>
					<li class="sidebar-menuitem"><a href="bookmeeting.html">预定会议</a></li>
					<li class="sidebar-menuitem"><a href="searchmeetings.html">搜索会议</a></li>
				</ul>
			</div>
		</div>
		<div class="page-content">
			<div class="content-nav">人员管理 > 员工注册</div>
			<form name=fromregister
				action="${pageContext.request.contextPath}/RegisterServlet"
				method="post">
				<fieldset>
					<legend>员工信息</legend>
					<table class="formtable" style="width: 50%">
						<tr>
							<td>姓名：</td>
							<td><input type="text" id="employeename" name="employeename"
								maxlength="20" /></td>
							<td><span id="employeenamespan"></span></td>
						</tr>
						<% 
							String accountname = request.getParameter("accountname");
							if(accountname == null){
								accountname = "";
							}
						%>
						<tr>
							<td>账户名：</td>
							<!-- <td><input type="text" id="accountname" name="accountname"
								maxlength="20""/></td> -->
							<td><input type="text" id="accountname" name="accountname"
								maxlength="20" onchange="validate()" value="<%=accountname %>"/></td>
							<td><span id="accountnamespan"></span></td>
						</tr>
						<tr>
							<td>密码：</td>
							<td><input type="password" id="password" name="password"
								maxlength="20" placeholder="请输入6位以上的密码" /></td>
							<td><span id="passwordspan"></span></td>
						</tr>
						<tr>
							<td>确认密码：</td>
							<td><input type="password" id="confirm" name="confirm"
								maxlength="20" /></td>
							<td><span></span></td>
						</tr>
						<tr>
							<td>联系电话：</td>
							<td><input type="text" id="phone" name="phone"
								maxlength="20" /></td>
							<td><span id="phonespan"></span></td>
						</tr>
						<tr>
							<td>电子邮件：</td>
							<td><input type="text" id="email" name="email"
								maxlength="20" /></td>
							<td><span id="emailspan"></span></td>
						</tr>
						<td>所在部门：</td>
						<td><select name="deptid">
								<!-- <option value="1">技术部</option>
                                     	<option value="2">财务部</option>
										<option value="3">人事部</option> -->
								<%
									selectAll se = new selectAll();
									List<department> list = se.selectDepartment();
									Iterator<department> it = list.iterator();
									while (it.hasNext()) {
										department de = it.next();
										out.print("<option value = '");
										out.print(de.getDepartmentid() + "'>");
										out.print(de.getDepartmentname());
										out.print("</option>");
									}
								%>
						</select></td>
						</tr>
						<tr>
							<td colspan="6" class="command"><input type="submit"
								class="clickbutton" value="注册" onclick="clickbutton" /> <input
								type="reset" class="clickbutton" value="重置" /></td>
						</tr>
					</table>
				</fieldset>
			</form>
		</div>
	</div>
	<div class="page-footer">
		<hr />
		更多问题，欢迎联系<a href="mailto:webmaster@eeg.com">管理员</a> <img
			src="../images/footer.png" alt="CoolMeeting" />
	</div>
</body>
</html>